package parsing.parsers;

import parsing.datasource.IDataSource;
import parsing.patternsource.IPatternSource;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created with IntelliJ IDEA.
 * User: platonovv
 * Date: 29.11.13
 * To change this template use File | Settings | File Templates.
 */
public class SomeNotVeryOptimalParser implements IParser<String, String> {
    private Map<String, String> result;

    public Map<String, String> parse(IPatternSource p, IDataSource d) {
        result = new HashMap<String, String>();
        for (String dataLine : d.getData()) {
            for (Pattern pattern : p.getPatterns()) {
                Matcher matcher = pattern.matcher(dataLine);
                while (matcher.find())
                    result.put(matcher.group(1), matcher.group(2));
            }
        }
        return result;
    }
}
